package org.example.Controller;

import org.example.Pojo.User;
import org.example.Service.Impl.PermissionServiceImpl;
import org.example.Service.Impl.UserServiceImpl;
import org.example.Utils.RequirePermission;
import org.example.Utils.UnionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping(value = "/User")
public class UserController {
    @Autowired
    UserServiceImpl userService;
    @RequestMapping(value = "/Register" )
    public UnionResult Register(User user) {

        return userService.Register(user);
    }
    @RequestMapping(value = "/Login")
    public UnionResult Login(User user) {
        return userService.Login(user);
    }
    @RequirePermission("m:user")
    @RequestMapping("/QueryAllUser")
    public UnionResult QueryAllUser() {
        return userService.GetAllUsers();
    }
    @RequestMapping(value = "/UpdateInfo")
    public UnionResult UpdateInfo(User user) {
        return userService.UpdateInfo(user);
    }
    @RequestMapping(value = "/UpdatePassword")
    public UnionResult UpdatePassword(User user) {
        return userService.UpdatePassword(user);
    }
    @RequestMapping(value = "/UpdateAvatar")
    public UnionResult UpdateAvatar(@RequestParam("file")MultipartFile[] file,User user) throws IOException {
        return userService.UpdateAvatar(file[0],user);
    }
    @RequestMapping(value = "/QueryUserInfo")
    public UnionResult QueryUserInfo(String uid) {
        return userService.GetUserInfo(uid);
    }
    @RequestMapping(value = "/ActiveUser")
    public UnionResult ActiveUser(User user) {
        return userService.ActiveUser(user);
    }
}
